package controller;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JTextField;

public class AccentButtonListener extends AbstractActionListener implements KeyListener
{
	private String spanishLetter;
	private String keyboardLetter;
	private JTextField input; 

	public AccentButtonListener(String letter, String keyboardLetter, JTextField input)
	{
		super(null);
		this.spanishLetter = letter;
		this.keyboardLetter = keyboardLetter;
		this.input = input;
	}

	@Override
	public void keyPressed(KeyEvent e)
	{
		if(e.isShiftDown() && e.isAltDown() && e.getKeyCode() == KeyEvent.getExtendedKeyCodeForChar(keyboardLetter.charAt(0)))
		{
			myAction();
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {}

	@Override
	public void keyTyped(KeyEvent e) {}

	@Override
	protected void myAction()
	{
		String currentText = input.getText();
		String newText = currentText + spanishLetter;
		this.input.setText(newText);
		this.input.requestFocus();
	}
}